package cn.s1995.sloth.bizs.exception;

import cn.s1995.sloth.common.core.constant.enums.hint.HintEnum;
import cn.s1995.sloth.common.core.util.MsgUtils;
import lombok.Data;

/**
 * BizException
 *
 * @author Lex
 * @description 自定义业务异常类
 * @date 2024/1/29 09:56
 */
@Data
public class BizException extends RuntimeException {

    /**
     * 提示枚举
     */
    private HintEnum hintEnum;


    public BizException(HintEnum hint, Object... args) {
        super(buildI18nMsg(hint, args));
        this.hintEnum = hint;
    }

    /**
     * 构建国际化消息
     *
     * @param hint
     * @param args
     * @return
     */
    private static String buildI18nMsg(HintEnum hint, Object... args) {
        // 获取国际化消息
        String i18nMsg = MsgUtils.getMessage(hint, args).getMsg();
        hint.setMsg(i18nMsg);
        return i18nMsg;
    }

}
